<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
      <!-- <el-form-item label="检验开始日期" prop="`inspectionBegins`">
                <el-date-picker clearable
                    v-model="queryParams.inspectionBegins"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择巡检开始日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="检验结束日期" prop="inspectionEnddate">
                <el-date-picker clearable
                    v-model="queryParams.inspectionEnddate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请选择巡检结束日期">
                </el-date-picker>
      </el-form-item>-->
      <el-form-item label="生产工单" prop="workorderCode">
        <el-input
          v-model="queryParams.workorderCode"
          placeholder="请输入工单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="SN码" prop="snCode">
        <el-input
          v-model="queryParams.snCode"
          placeholder="请输入SN码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检验员" prop="checkBy">
        <el-input
          v-model="queryParams.checkBy"
          placeholder="请输入检验员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker
          clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="检验结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择检验结果" clearable>
          <el-option
            v-for="item in inspectResult"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="产线" prop="workorderCode">
        <el-select v-model="queryParams.workorderCode" placeholder="请选择产线" clearable>
          <el-option
            v-for="dict in lineList"
            :key="dict.lineId"
            :label="dict.lineName"
            :value="dict.lineId"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="ipqcList">
      <el-table-column type="index" label="序号" align="center" width="50" />
      <el-table-column label="检验单编号" align="center" width="175" prop="ipqcAllCode">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row)"
          >{{ scope.row.ipqcAllCode }}</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column label="审核状态" align="center" prop="examineStatus">
                <template slot-scope="scope">
                {{ scope.row.examineStatus==1?"创建":value.examineStatus }}
                </template>
      </el-table-column>-->
      <el-table-column label="产线" align="center" prop="lineName" />
      <el-table-column label="生产工单" align="center" prop="workorderCode" width="120" />
      <el-table-column label="SN码" align="center" width="110" prop="snCode" />
      <el-table-column label="产品编号" width="120" align="center" prop="productCode" />
      <el-table-column
        label="产品名称"
        width="160"
        align="center"
        prop="productName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格型号"
        width="180"
        align="center"
        prop="productSpec"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="流程状态" align="center" prop="flowStatus">
        <!-- <template slot-scope="scope">
                  <dict-tag :options="dict.type.ipqcLine_submissionStatus" :value="scope.row.submissionStatus" />
        </template>-->
        <template
          slot-scope="scope"
        >{{ scope.row.flowStatus =='3' ? "生产确认" :scope.row.flowStatus =='1'?"产线返工":scope.row.flowStatus =='2'?"IPQC检验":scope.row.flowStatus =='4'?"检验完成":"--" }}</template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" width="160" prop="createTime" />
      <el-table-column label="检验状态" align="center" prop="checkStatus">
        <template slot-scope="scope">
          <div :style="{ color: scope.row.checkStatus =='0' ? 'orange' : '' }">
            {{ scope.row.checkStatus =='0' ? "未检验" :scope.row.checkStatus =='1'?"已检验":"--" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="检验员" align="center" prop="checkBy" />
      <el-table-column label="检验结果" align="center" prop="checkResult">
        <template slot-scope="scope">
          <div :style="{ color: scope.row.checkResult =='0' ? 'red' : 'green' }">
            {{ scope.row.checkResult =='0' ? "不合格" :scope.row.checkResult =='1'?"合格":"--" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="检验日期" align="center" width="120" prop="checkTime" />

      <!-- <el-table-column label="审核员" align="center" prop="auditor" />
      <el-table-column label="审核日期" align="center" prop="shenheriqi" />-->

      <!-- <el-table-column label="检验日期" align="center" prop="inspectDate" width="180">
                <template slot-scope="scope">
                <span>{{ parseTime(scope.row.inspectDate, '{y}-{m}-{d}') }}</span>
                </template>
      </el-table-column>-->

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="160"
      >
        <template slot-scope="scope">
          <!-- v-if="scope.row.checkResult !='1' && scope.row.reportStatus != '0'" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUserRole(scope.row)"
            v-if="scope.row.flowStatus=='2'"
            v-hasPermi="['mes:qc:qcindex:edit']"
          >检验</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="submitIpqcall(scope.row)"
            v-if="scope.row.flowStatus=='1'"
            v-hasPermi="['mes:qc:qcindex:edit']"
          >提交</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="checkRejectDetail(scope.row,{},{})"
            v-hasPermi="['mes:qc:qcindex:edit']"
          >驳回详情</el-button>
          <!-- <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleUpdate(scope.row)"
                    v-hasPermi="['mes:qc:ipqc:edit']"
          >发起审核</el-button>-->
          <!-- <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="details(true,scope.row)"
                    v-hasPermi="['mes:qc:ipqc:remove']"
          >日报表</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- <daily-report  v-if="dailyReport" ref="dailyReport"></daily-report> -->

    <!-- 添加或修改检测项对话框 -->
    <el-drawer
      :title="title"
      :visible.sync="open"
      size="80%"
      :before-close="cancel"
      custom-class="demo-drawer"
      @close="cancel"
    >
      <div class="demo-drawer__content dialogContent">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="100px"
          style="padding:0 15px "
        >
          <el-tag size="large" style="font-size: 20px">基本信息</el-tag>
          <hr />
          <el-row>
            <el-col :span="8">
              <el-form-item label="工单编码" prop="workorderCode">
                <el-input v-model="form.workorderCode" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="sn码" prop="snCode">
                <el-input v-model="form.snCode" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="所属产线" prop="lineName">
                <el-input v-model="form.lineName" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="产品编码" prop="productCode">
                <el-input v-model="form.productCode" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="产品名称" prop="productName">
                <el-input v-model="form.productName" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="产品规格" prop="productSpec">
                <el-input v-model="form.productSpec" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="检验状态" prop="checkStatus">
                <el-select
                  v-model="form.checkStatus"
                  placeholder="请选择检验结果"
                  clearable
                  :disabled="true"
                >
                  <el-option label="未检验" value="0" />
                  <el-option label="已检验" value="1" />
                </el-select>
                <!-- <el-input v-model="form.checkStatus" placeholder :disabled="true" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="检验员" prop="checkBy">
                <el-input v-model="form.checkBy" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="检验时间" prop="checkTime">
                <el-input v-model="form.checkTime" placeholder :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-tag size="large" style="font-size: 20px">产线明细</el-tag>
          <hr />
          <!-- 产线明细 -->
          <el-row style="margin-bottom: 15px">
            <el-table v-loading="loading1" :data="templateLineList" max-height="300px">
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column label="所属工位" prop="workstationName" />
              <el-table-column label="提交状态" align="center" prop="submissionStatus">
                <!-- <template slot-scope="scope">
                  <dict-tag :options="dict.type.ipqcLine_submissionStatus" :value="scope.row.submissionStatus" />
                </template>-->
                <template
                  slot-scope="scope"
                >{{ scope.row.submissionStatus =='0' ? "未提交" :scope.row.submissionStatus =='1'?"已提交":scope.row.submissionStatus =='2'?"已驳回":"--" }}</template>
              </el-table-column>
              <el-table-column label="提交人" prop="submissionBy" />
              <el-table-column label="提交时间" prop="submissionTime" />
              <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
                fixed="right"
                width="160"
              >
                <template slot-scope="scope">
                  <!-- @click="handleUserRole(scope.row)" -->
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    v-hasPermi="['mes:qc:qcindex:edit']"
                    @click="rejectQuery(scope.row)"
                    v-if="(rejectOpen && scope.row.submissionStatus =='1')"
                  >驳回</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    v-hasPermi="['mes:qc:qcindex:edit']"
                    @click="checkRejectDetail(form,{},scope.row)"
                  >驳回详情</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-row>
          <div v-if="submitReault">
            <el-tag size="large" style="font-size: 20px;">检验项目（机箱检查）</el-tag>
            <hr />
            <el-row>
              <el-table v-loading="loading1" :data="templateList" :span-method="objectSpanMethod">
                <el-table-column label="类型" align="center" prop="indexType" width="180px">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.mes_index_type" :value="scope.row.indexType" />
                  </template>
                </el-table-column>
                <el-table-column type="index" width="50"></el-table-column>
                <el-table-column label="检测项目" prop="indexName" />

                <el-table-column align="center" prop="checkResult" width="240px" label="检查结果">
                  <!-- <template slot="header" slot-scope="scope">
                  <div class="headerDiv" v-if="optType=='add' || optType=='edit'">
                    <el-input
                      v-model="snObj[`snCode${i}`]"
                      size="mini"
                      placeholder="输入sn码"
                      @input="snbutton"
                      id="sncode-input"
                    />
                  </div>
                  <div v-if="optType=='view'">{{ snObj[`snCode${i}`] }}</div>
                  </template>-->
                  <template slot-scope="scope">
                    <div v-if="optType=='add' || optType=='edit'">
                      <el-radio-group v-model="scope.row.checkResult" @input="checkChange">
                        <el-radio :label="1" value="1">√</el-radio>
                        <el-radio :label="0" value="0">×</el-radio>
                      </el-radio-group>
                      <ul v-if="scope.row.attrObj.type=='2'">
                        <li class="mInput">
                          <span>标准值</span>
                          <el-input
                            v-model="scope.row.attrObj.standard"
                            style="width: 70px;"
                            @input="(e)=> inputStandard(e,scope.row,scope.$index)"
                          />
                          <el-input
                            v-model="scope.row.attrObj.num"
                            style="width: 70px;"
                            @input="(e)=> inputStandard(e,scope.row,scope.$index)"
                          />
                        </li>
                      </ul>
                      <ul v-if="scope.row.attrObj.type=='4'">
                        <li class="mInput">
                          <span>长</span>
                          <el-input
                            v-model="scope.row.attrObj.lStandard"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                          <el-input
                            v-model="scope.row.attrObj.lNum"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                        </li>
                        <li class="mInput">
                          <span>宽</span>
                          <el-input
                            v-model="scope.row.attrObj.wStandard"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                          <el-input
                            v-model="scope.row.attrObj.wNum"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                        </li>
                        <li class="mInput">
                          <span>高</span>
                          <el-input
                            v-model="scope.row.attrObj.hStandard"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                          <el-input
                            v-model="scope.row.attrObj.hNum"
                            style="width: 70px;"
                            @input="(e)=> inputCheckout(e,scope.row,scope.$index)"
                          />
                        </li>
                      </ul>
                    </div>
                    <div v-if="optType=='view'">
                      <div
                        style="font-size:20px"
                      >{{ scope.row.checkResult =='0' ? "×" :scope.row.checkResult =='1'?"√":"--" }}</div>
                      <div v-if="scope.row.attrObj.type=='2'">
                        <div class="mInput">
                          <span>标准值</span>
                          <span>{{ scope.row.attrObj.standard}}：</span>
                          <span>{{ scope.row.attrObj.num }}</span>
                        </div>
                      </div>
                      <ul v-if="scope.row.attrObj.type=='4'">
                        <li class="mInput">
                          <span>长</span>
                          <span>{{ scope.row.attrObj.lStandard }},</span>
                          <span>{{ scope.row.attrObj.lNum }}</span>
                        </li>
                        <li class="mInput">
                          <span>宽</span>
                          <span>{{ scope.row.attrObj.wStandard }},</span>
                          <span>{{ scope.row.attrObj.wNum }}</span>
                        </li>
                        <li class="mInput">
                          <span>高</span>
                          <span>{{ scope.row.attrObj.hStandard }},</span>
                          <span>{{ scope.row.attrObj.hNum }}</span>
                        </li>
                      </ul>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
            </el-row>
            <el-row>
              <el-col :span="24" class="imgDiv">
                <el-form-item label="检验结果" prop="checkResult">
                  <el-radio-group v-model="form.checkResult">
                    <el-radio :label="1">√</el-radio>
                    <el-radio :label="0">×</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <!-- :disabled="form.state =='0'?false:true" -->
              <el-col :span="24">
                <el-form-item label="备注:" prop="remark">
                  <el-input
                    v-model="form.remark"
                    type="textarea"
                    placeholder="输入备注"
                    style="width: 450px; height: 50px"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 不合格品异常记录列表 -->
            <div v-if="form.checkResult ==0">
              <el-form-item label="不合格品处理方式" prop="resultWay">
                <el-radio-group v-model="form.resultWay" v-if="optType != 'view'">
                  <el-radio :label="1">返工</el-radio>
                  <el-radio :label="2">返修</el-radio>
                </el-radio-group>
                <span v-if="optType == 'view'">
                  ：
                  {{ form.resultWay=='1'?'返工':form.resultWay=='2'?"返修":"--" }}
                </span>
              </el-form-item>

              <el-form-item label="异常记录">
                <el-table :data="exceptionLogList">
                  <el-table-column label="类型选择" align="center" prop="indexType">
                    <template slot-scope="scope">
                      <el-select v-model="scope.row.indexType" placeholder="请选择检测项类型" clearable>
                        <el-option
                          v-for="dict in errorTypeList"
                          :key="dict.name"
                          :label="dict.name"
                          :value="dict.name"
                        />
                      </el-select>
                    </template>
                  </el-table-column>

                  <el-table-column label="异常描述" align="center" prop="describeData">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.describeData" placeholder type="textarea" />
                    </template>
                  </el-table-column>
                  <el-table-column label="文件上传" align="center" prop="fileName">
                    <template slot-scope="scope">
                      <ImageUpload
                        :limit="1"
                        :value="scope.row.fileName"
                        :fileSize="15"
                        @input="(url)=>handleImgUplaoded(url,scope.$index)"
                        @onRemoved="(url)=>handleImgRemoved(url,scope.$index)"
                      ></ImageUpload>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="medium"
                        type="text"
                        icon="el-icon-circle-plus-outline"
                        @click="errorAdd(item)"
                      ></el-button>
                      <el-button
                        v-if="scope.$index != 0"
                        size="medium"
                        type="text"
                        icon="el-icon-remove-outline"
                        @click="errorDel(scope.$index)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-form-item>
            </div>
          </div>
        </el-form>
      </div>
      <div class="demo-drawer__footer" style="text-align: right;">
        <el-button type="primary" @click="cancel" v-if="optType =='view'">返回</el-button>
        <el-button type="primary" @click="submitForm" v-else :disabled="rejectOpen">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-drawer>
    <!-- src="./HKZN-WI-03-334-国网六统一60kw单枪装配作业指导书.xlsx" -->
    <!-- <vue-office-excel
      :src="excel"
      style="height: 100vh;"
      @rendered="renderedHandler"
      @error="errorHandler"
    />
    <vue-office-docx
        :src="docx"
        style="height: 100vh;"
        @rendered="renderedHandler"
        @error="errorHandler"
    />-->
    <!-- <iframe :src="docx" width="100%" height="100vh" ></iframe> -->

    <RejectLine ref="rejectLines" v-if="openLine" @getlineList="getlineList"></RejectLine>
    <RejectDetails ref="rejectDetails" v-if="openLineDetail"></RejectDetails>

    <DetailsList v-if="openDetail" ref="detailsList"></DetailsList>
  </div>
</template>
    
<script>
// import dailyReport from "./dailyReport.vue";
//引入VueOfficeExcel组件
import VueOfficeExcel from "@vue-office/excel";
//引入相关样式
import "@vue-office/excel/lib/index.css";
//引入VueOfficeDocx组件
import VueOfficeDocx from "@vue-office/docx";
//引入相关样式
import "@vue-office/docx/lib/index.css";
import { selectUserRole } from "@/api/mes/pro/workorder";
import {
  productionlineList,
  getData,
  getLineProductInfo,
  addInspection,
  submitQcIpqcAll
} from "@/api/mes/qc/qcipqcAll";
import { templateindexList, listError } from "@/api/mes/qc/fqc";

// 驳回
import RejectLine from "./components/rejectLine.vue";
// 驳回详情
import RejectDetails from "./components/rejectDetail.vue";
import DetailsList from "./components/detailsList.vue";
export default {
  name: "ipqcall",
  // 产线提交明细 提交状态字典 ipqcLine_submissionStatus  IPQC全检检验状态字典  ipqcAll_checkStatus  IPQC全检流程状态字典  ipqcAll_flowStatus
  dicts: [
    "mes_index_type",
    "mes_qc_result",
    " ipqcLine_submissionStatus",
    "ipqcAll_checkStatus",
    "ipqcAll_flowStatus"
  ],
  data() {
    return {
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        inspectionBegins: "",
        inspectionEnddate: "",
        productionline: "",
        workorderCode: null,
        snCode: null,
        checkBy: null,
        createTime: null,
        checkResult: null,
      },
      // 总条数
      total: 0,
      title: "",
      optType: "",
      open: false,
      //展示用的产线列表
      productionLine: [],
      excel:
        "http://68ffd19d.r11.cpolar.top/mes/file/download/2024-02/HKZN-WI-03-334-国网六统一60kw单枪装配作业指导书_1709019124923.xlsx",
      // docx:"http://192.168.2.32:9088/mes/file/download/2024-02/拍摄需求_1708938997262.docx",
      //保存的产线列表
      lineList: [],
      templateLineList: [],
      // 遮罩层
      loading: false,
      // 表格数据
      ipqcList: [],
      //日报表
      dailyReport: false,
      // 表单参数
      form: {},
      // sncode集合
      snObj: {},
      radioObj: {},
      // 表单校验
      rules: {
        snCode: [{ required: true, message: "SN码不能为空", trigger: "blur" }],
        unqualifiedCode: [
          { required: true, message: "不合格数量不能为空", trigger: "blur" }
        ],
        qualifiedCode: [
          { required: true, message: "合格数量不能为空", trigger: "blur" }
        ],
        checkResult: [
          { required: true, message: "检验结果不能为空", trigger: "change" }
        ],

        headEndCheckType: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ]
      },
      indexCodeDisabled: false,
      // 模板列表
      templateList: [],
      loading1: false,
      spanArr: [],
      // 异常记录列表
      exceptionLogList: [{}],
      // 不合格数
      failedSncode: [],
      // 首页列表信息
      QcFqcAcInspectionHead: {},
      errorTypeList: [
        {
          name: "标识不良"
        },
        {
          name: "名牌不良"
        },
        {
          name: "LOGO、丝印不良"
        },
        {
          name: "机箱外观不良"
        },
        {
          name: "线材不良"
        },
        {
          name: "物料不良"
        },
        {
          name: "螺钉记号不良"
        },
        {
          name: "螺钉漏打"
        },
        {
          name: "螺钉未打紧"
        },
        {
          name: "接线不良"
        },
        {
          name: "接线紧固不良"
        },
        {
          name: "装配不良"
        },
        {
          name: "接线走线不符合工艺要求"
        },
        {
          name: "打胶不良"
        },
        {
          name: "配件不齐"
        },
        {
          name: "挡板、挡板螺丝漏"
        }
      ],
      snCodeAllList: [],
      snList: [],
      rejectOpen: false,
      openDetail: false,
      //检验状态
      inspectState: [
        {
          value: 0,
          label: "未检验"
        },
        {
          value: 1,
          label: "已检验"
        }
      ],
      //检验结果
      inspectResult: [
        {
          value: 1,
          label: "合格"
        },
        {
          value: 0,
          label: "不合格"
        }
      ],
      // 提交结果
      submitReault: null,
      openLine: false,
      openLineDetail: false,
      qcIpqcallInspectionRecords: {}
    };
  },
  components: {
    VueOfficeExcel,
    VueOfficeDocx,
    RejectLine,
    RejectDetails,
    DetailsList
  },
  created() {
    this.getList();
  },
  methods: {
    renderedHandler() {
      console.log("渲染完成");
    },
    errorHandler(e, data) {
      console.log(e, data, "渲染失败");
    },
    //获取产线列表
    getlineList(obj) {
      // let params={
      //   'bomItemCode':obj.bomItemCode,
      //   'productCode':obj.productCode,
      //   'productId':obj.productId
      // }
      getLineProductInfo(obj).then(res => {
        console.log(res, "产线列表res");
        if (res.code == 200) {
          this.templateLineList = res.data;
          this.submitReault = this.templateLineList.every(
            item => item.submissionStatus == 1 || item.submissionStatus == 2
          );
          console.log(bool, "-======bool=========");
        }
      });
    },
    //请求数据
    getList() {
      let param = this.queryParams;
      this.loading = true;
      getData(param).then(res => {
        console.log(res, "请求数据的res");
        if (res.code == 200) {
          this.total = res.total;
          this.ipqcList = res.rows;
          this.loading = false;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 发起审核
    handleUpdate() {},

    handleUserRole(row) {
      // this.statusQuery(row,type)
      selectUserRole("FQC_质检员工")
        .then(res => {
          this.handleAdd(row);
        })
        .catch(() => {
          console.log("qqqqqqqqq");
          return "false";
        });
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      // this.reset();
      this.indexCodeDisabled = false;
      this.open = true;
      this.QcFqcAcInspectionHead = row;
      this.rejectOpen = false;
      this.form = { ...row };
      console.log(this.form, "========form==========");
      this.title = "IPQC全检单";
      this.optType = "add";
      let id = "22";
      // getFqcSnCode(this.form.inspectionNumber).then(response => {
      //   this.snCodeAllList = response.data.map((item, index) => {
      //     return item.snCode;
      //   });
      // });
      this.getlineList(row);
      this.templatePost(id);
      // this.getErrorlist(row.productType, id);
    },
    // 取消按钮
    cancel() {
      if (this.form.checkResult == 0 && this.rejectOpen) {
        let bool = this.templateLineList.some(
          item => item.submissionStatus == "2"
        );
        console.log(bool, "-======bool=========");
        if (!bool) {
          this.$message({
            message: "请选择需驳回的工位!!!",
            type: "warning"
          });
          return;
        } else {
          this.open = false;
          this.reset();
          this.getList();
        }
      } else {
        this.open = false;
        this.reset();
        this.getList();
      }
    },
    // 表单重置
    reset() {
      this.form = {
        checkResult: null,
        snCode: null,
        indexName: null,
        indexType: null,
        headEndCheckType: null,
        remark: null
      };
      this.snObj = {};
      this.radioObj = {};
      this.templateList = [];
      this.autoGenFlag = false;
      this.loading1 = false;
      this.exceptionLogList = [{}];
      this.snCodeAllList = [];
      this.snList = [];
      // 不合格数
      this.failedSncode = [];
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.templateList, "=====templateList===");
      console.log(this.form, "========this.form=======");
      let QcIpqcAllDto = {};
      let bool = false;
      QcIpqcAllDto.qcIpqcAllItemList = this.templateList;
      QcIpqcAllDto.qcInspectionResult = {
        productType: this.form.productType,
        exceptionLogList: this.exceptionLogList,
        inspectionType: "5",
        checkResult: this.form.checkResult,
        resultWay: this.form.resultWay,
        snCode: this.form.snCode
      };
      QcIpqcAllDto.qcIpqcAll = {
        ...this.form
      };
      console.log(QcIpqcAllDto, "======QcIpqcAllDto=========");
      for (let j = 0; j < this.templateList.length; j++) {
        const element = this.templateList[j].checkResult;
        console.log(element);
        if (element === undefined) {
          bool = true;
        }
      }
      if (bool) {
        this.$message({
          message: "请填写检验结果！！！",
          type: "warning"
        });
        return;
      }

      this.$refs["form"].validate((valid, value) => {
        console.log(valid, value, "===valid===");

        if (valid) {
          addInspection(QcIpqcAllDto).then(response => {
            this.$modal.msgSuccess("新增成功");
            // this.open = false;
            this.rejectOpen = true;
            this.qcIpqcallInspectionRecords = response.data || {};
            // this.reset();
            // this.getList();
          });
        } else {
        }
      });
    },
    // 获取新增表格列表
    templatePost(id) {
      this.loading1 = true;
      let params = {
        pageNum: 1,
        pageSize: 999999,
        templateId: id || "18"
      };
      templateindexList(params).then(response => {
        let list = [];
        response.rows.map((item, index) => {
          list.push(
            Object.assign({}, item, {
              attrObj: item.attr1 ? JSON.parse(item.attr1) : { type: "0" }
            })
          );
        });
        this.templateList = list;
        console.log(this.templateList, "=========list===========");
        this.getSpanArr(response.rows);

        // this.errorTypeList = this.templateList.map(item => {
        //   return item.inspectionItem;
        // });
        this.loading1 = false;
      });
    },
    getErrorlist(type, id) {
      console.log(type, id, "===========idddd====");
      let params = {};
      params.productType = type || "DC";
      params.templateId = id;
      console.log(params, "params");
      listError(params).then(response => {
        this.errorTypeList = response.data;
        console.log(response, "异常记录list");
      });
    },
    // 行合并
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]; // 合并行数
        const _col = this.spanArr[rowIndex] > 0 ? 1 : 0; // 合并的列数
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },
    // 按照类型合并
    getSpanArr(data) {
      this.spanArr = []; // tip: 后台获取完成数据后，一定要重置spanArr=[],避免出现合并混乱！！！！！
      if (data.length > 0) {
        for (let i = 0; i < data.length; i++) {
          // 当为第一行时
          if (i === 0) {
            this.spanArr.push(1);
            this.pos = 0;
          } else {
            // 判断当前值是否与上一行的【名称】相等，相等则进行合并
            if (data[i].indexType === data[i - 1].indexType) {
              this.spanArr[this.pos] += 1; // 合并单元格：合并的行数 +1
              this.spanArr.push(0); // 0代表单元格是不需要显示, 已经被合并的单元格
            } else {
              this.spanArr.push(1); // 1代表当前这行的数据需要被显示
              this.pos = i;
            }
          }
        }
      }
    },
    //全选按钮事件
    checkAllChange(value, i) {
      console.log(value, i, "=====iii=======");
      let objName = "checkResult" + i;
      let list = [];
      this.templateList.map((item, index) => {
        list.push(Object.assign({}, item, { [objName]: 1 }));
      });
      console.log(list);
      this.templateList = list;
    },
    // 判断是否显示打钩单选
    judegShow(attr) {
      return true;
    },
    // 判断当前是否是合格
    checkChange(value) {
      let str = "checkResult";
      let bool = this.templateList.every(item => item[str] == 1);
      this.form.checkResult = bool ? 1 : 0;
    },
    // 异常记录增加
    errorAdd(item, i) {
      let obj = {};
      this.exceptionLogList.push(obj);
    },
    // 删除异常记录
    errorDel(index, i) {
      this.exceptionLogList.splice(index, 1);
    },
    //图片上传成功
    handleImgUplaoded(imgUrl, index) {
      this.exceptionLogList[index].fileName = imgUrl;
      // this.form.sopUrl = imgUrl;
    },
    //图片移除
    handleImgRemoved(imgUrl, index) {
      console.log(imgUrl);
      this.exceptionLogList[index].fileName = imgUrl;
    },
    inputStandard(e, row, index) {
      console.log(row, "=====row=====");
      let judType = row.attrObj.judType;
      let num = row.attrObj.num;
      let standard = row.attrObj.standard;
      let min = row.attrObj.min;
      let max = row.attrObj.max;
      if (judType == "0") {
        // =
        if (num == standard) {
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "1") {
        // >=
        if (Number(num) >= Number(standard)) {
          console.log(num, "==1=");
          this.templateList[index].checkResult = 1;
        } else {
          console.log(num, "=0==");
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "2") {
        // <=
        if (Number(num) <= Number(standard)) {
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      } else if (judType == "3") {
        if (Number(num) >= Number(min) && Number(num) <= Number(max)) {
          console.log(true, "=====");
          this.templateList[index].checkResult = 1;
        } else {
          this.templateList[index].checkResult = 0;
        }
      }
      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
      this.checkChange();
    },
    inputCheckout(e, row, index) {
      let lStandard = row.attrObj.lStandard;
      let wStandard = row.attrObj.wStandard;
      let hStandard = row.attrObj.hStandard;
      let lnum = row.attrObj.lNum;
      let wnum = row.attrObj.wNum;
      let hnum = row.attrObj.hNum;
      if (lnum == lStandard && wnum == wStandard && hnum == hStandard) {
        console.log(true, "=====");
        this.templateList[index].checkResult = 1;
      } else {
        this.templateList[index].checkResult = 0;
      }

      let obj1 = { ...this.templateList[index] };
      this.$set(this.templateList, index, obj1);
      this.checkChange();
    },

    handleViewBom(row) {
      this.reset();
      this.openDetailBom = true;
      console.log(row, "领料单编号的row");
      this.$nextTick(() => {
        this.$refs.detailsBom.init(row);
      });
    },

    selectChange(e) {
      console.log(e, "====e=====");
      if (e === "0") {
        this.snList = this.snCodeAllList;
      } else {
        this.snList = [];
      }
    },
    // 自动计算合格不合格数量
    autoInput(e, type, name) {
      if (e > this.form.quantityDeclared) {
        this.$message({
          message: "数量不允许超过报检数量！！！",
          type: "warning"
        });
        this.form[type] = 0;
      } else {
        this.form[name] = this.form.quantityDeclared - this.form[type];
      }
      // this.form[name] =  this.form.quantityDeclared - this.form[type]
    },
    // 产线驳回
    rejectQuery(row) {
      this.openLine = true;
      this.$nextTick(() => {
        this.$refs.rejectLines.init(
          row,
          this.form,
          this.qcIpqcallInspectionRecords
        );
      });
    },

    // 提交 submitQcIpqcAll
    submitIpqcall(row) {
      this.$modal
        .confirm('是否确认提交检验单编号为"' + row.ipqcAllCode + '"的数据项？')
        .then(function() {
          return submitQcIpqcAll(row);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("提交成功");
        })
        .catch(() => {});
    },

    // 驳回详情
    checkRejectDetail(row, data, obj) {
      this.openLineDetail = true;
      this.$nextTick(() => {
        this.$refs.rejectDetails.init(row, data, obj);
      });
    },
    // 详情
    handleView(row) {
      this.reset();
      this.openDetail = true;
      console.log(row, "===row");
      this.$nextTick(() => {
        this.$refs.detailsList.init(row);
      });
    }
  }
};
</script>
<style scoped>
</style>
     